package com.app.TCES.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import org.springframework.stereotype.Component;

import com.app.TCES.domain.Student;


@Component
@Mapper
public interface UploadMapper {

	//添加
	@Insert("insert into student (stuId,stuName,deptId,classId) values (#{student.stuId},#{student.stuName},#{student.deptId},#{student.classId})")
	void BatchAdd(@Param("student")Student student);
	//通过学院名称查找学院编号
	@Select("select deptId from department where deptName=#{deptName}")
	int selectDeptId(@Param("deptName")String deptName);
	
	//通过班级名称查找班级编号
	@Select("select classId from class where className =#{className}")
	int selectClassId(@Param("className")String className);
	
	//通过学号查询是否存在
	@Select("select count(*) from student where stuId=#{stuId}")
	int stuIdTotal(@Param("stuId")int stuId);
	
	//通过学号更改信息
	@Update("update student set stuName=#{student.stuName},deptId=#{student.deptId},classId=#{student.classId} where stuId=#{student.stuId}")
	void Ustudent(@Param("student")Student student);
	
	//批量插入
	@Insert({
		"<script>",
		"insert into student (stuId,stuName,deptId,classId) ",
		"values ",
		"<foreach collection=\"list\" item=\"item\" index=\"index\"  separator=\",\"> ",
		"(#{item.stuId}, #{item.stuName}, #{item.deptId},#{item.classId}) ",
		"</foreach>",
		"</script>"
	})
	int insertBatch(List<Student> students);
	/*
	 * //批量操作
	 * 
	 * @InsertProvider(type = Provider.class, method = "batchInsert") int
	 * batchInsert(List<Student> students); class Provider{ //批量插入
	 * 
	 * @SuppressWarnings("unchecked") public String batchInsert(Map<String,Object>
	 * map) { List<Student> students = (List<Student>)map.get("list"); StringBuilder
	 * sb = new StringBuilder();
	 * sb.append("insert into student (stuId,stuName,deptId,classId) values");
	 * MessageFormat mf = new MessageFormat(
	 * "(#'{'list[{0}].stuId},#'{'list[{0}].stuName},#'{'list[{0}].deptId},#'{'list[{0}].classId})"
	 * ); for (int i = 0; i < students.size(); i++) { sb.append(mf.format(new
	 * Object[] {i})); if(i<students.size()-1) { sb.append(","); } } return
	 * sb.toString();
	 * 
	 * 
	 * } }
	 */
	
}
